/*
 * @Author: jhw
 * @Date: 2025-08-05 11:17:04
 * @LastEditors: jhw
 * @LastEditTime: 2025-08-14 23:19:45
 * @Description:
 */
import { educationStatus, genderStatus } from '@/configs/defaultStatus/initStatus';
import { isPicTitleDescArray, isStringArray, isValueArray } from '@/types';
import type { OptionsProps, Status, SurveyComName, TextProps } from '@/types';

export const getTextStatus = (status: TextProps) => {
  if (!status) return;
  return status.status;
};

export const getStringStatus = (props: OptionsProps) => {
  if (!props) return;
  if (props.status && isStringArray(props.status)) {
    return props.status;
  }
  // return props.status;
};

export const getCurrentStatus = (props: OptionsProps) => {
  if (!props) return;
  return props.currentStatus;
};

export const getStringStatusByCurrentStatus = (props: OptionsProps) => {
  if (!props) return;
  if (props.status && isStringArray(props.status)) {
    return props.status[props.currentStatus];
  }
};

export const getPicTitleDescStatusArr = (props: OptionsProps) => {
  if (!props) return;
  if (props.status && isPicTitleDescArray(props.status)) {
    return props.status;
  }
};

/**
 * @description 将传入number两位数补齐
 * @param num 传入的数字
 * @returns 返回补齐后的数字
 */
export const fillNumber = (num: number) => {
  return num.toString().padStart(2, '0');
};

export const updateInitStatusBeforeAdd = (status: Status, key: SurveyComName) => {
  switch (key) {
    case 'personal-info-gender': {
      status.name = 'personal-info-gender';
      status.status.title.status = '您的性别是？';
      status.status.options.status = genderStatus();
      break;
    }
    case 'personal-info-education': {
      status.name = 'personal-info-education';
      status.status.title.status = '到目前为止，您的最高学历是？';
      status.status.options.status = educationStatus();
      break;
    }
  }
};

export const getValueStatusByCurrentStatus = (props: OptionsProps) => {
  if (!props) return;
  if (props.status && (isValueArray(props.status) || isPicTitleDescArray(props.status))) {
    return props.status[props.currentStatus];
  }
};

/**
 * @description 移除coms每一项中的type 以及 每一项中的status中的teditCom
 * @param coms
 * @returns
 */
export const removeComsType = (coms: Status[]) => {
  return coms.map((com) => {
    delete com.type;
    if (com.status) {
      for (const key in com.status) {
        if (com.status[key as keyof typeof com.status].editCom) {
          delete com.status[key as keyof typeof com.status].editCom;
        }
      }
    }
    return com;
  });
};
